export default {
  data() {
    return {
      pages: {
        pageSize: 10,
        currPage: 1,
        listsCount: 10
      },
      items: [],
      loading: false,
      finished: false,
      isEmpty: false
    }
  },

  methods: {
    async resetInit(params) {
      this.resetData();
       this.initData();
       // console.log(this.pages);
      this.$nextTick(() => {

        this.setPages(this.pages);
      })
    },
    isFinished() {
      this.finished = true;
      this.loading = false;
    },
    async loadMore() {
      
      console.log('loadmore' + this.pages.listsCount);

      if (this.pages.listsCount < this.pages.pageSize) {
        // this.$toast({
        //   message: '没有更多了~'
        // });
        this.isFinished();
      } else {
        this.initData();
        this.nextPage(this.pages.listsCount);
      }
      this.loading = false;
    },
    nextPage(listsCount = 10) {
      this.pages.currPage++;
      this.pages.listsCount = listsCount;
    },
    setPages(page = {}) {
       console.log(this.pages.listsCount)
      this.isEmpty = (page.currPage === 1 && page.listsCount === 0);
      if (page.listsCount < this.pages.pageSize) {
        // 不满一页
        this.isFinished();
      } else {
        // 下一页
        this.nextPage(page.listsCount);
      }
    },
    resetData() {
      this.items = [];
      this.pages = {
        pageSize: 10,
        currPage: 1,
        listsCount: 10
      }
      this.loading = false;
      this.finished = false;
      this.isEmpty = false;
    }
  }
}
